package com.huangdada.hfweather.config;

import com.huangdada.hfweather.task.WeatherJob;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * @Description: Quartz配置类
 * @PROJECT_NAME: hf-weather
 * @CLASS_NAME:
 * @Author: huanglibin
 * @Date: 2020-03-30 22:29
 * @Version: 1.0
 */
@Slf4j
//@Configuration
public class WeatherQuartzConfig {

//    @Bean
    public JobDetail weatherQuartzTaskDetail(){
        return JobBuilder.newJob(WeatherJob.class).withIdentity("WeatherJob").storeDurably().build();
    }

//    @Bean
    public Trigger weatherQuartzTaskTrigger(){
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 31 1 1 * ?");
        return TriggerBuilder.newTrigger()
                //关联上述的JobDetail
                .forJob(weatherQuartzTaskDetail())
                //给Trigger起个名字
                .withIdentity("WeatherJob")
                .withSchedule(cronScheduleBuilder)
                .build();
    }
}
